﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using DAO;
using BUS;
using System.Xml;

namespace WebRaoVat
{
    public partial class ChiTietDanhMucChinh : System.Web.UI.Page
    {
        public string sqlDataSourceDMC(int index)
        {
            return "sqlDataSourceDanhMucCon" + index;
        }

        public List<DanhMucConDTO> danhMucCon = new List<DanhMucConDTO>();
        public List<SqlDataSource> sqlDataSourceList = new List<SqlDataSource>();
        public List<SqlDataSource> sqlDataSourceDanhMucCon = new List<SqlDataSource>();
        public string tenDanhMucChinh = "";
        public int maDanhMucChinh = 1;
       
        protected void Page_Load(object sender, EventArgs e)
        {
            try{
                maDanhMucChinh = int.Parse(Request.QueryString["danhmucchinh"].ToString());
            }catch(Exception){}
            danhMucCon = DanhMucConBUS.layDSDanhMucCon(maDanhMucChinh);

            tenDanhMucChinh = DanhMucChinhBUS.getTen(maDanhMucChinh);
            try
            {
                Session["TrangHienTai"] = "ChiTietDanhMucChinh.aspx?danhmucchinh=" + Request.QueryString["danhmucchinh"].ToString();
            }
            catch (Exception)
            {
            }

            for (int i = 0; i < 10; i++)
            {
                if (i < danhMucCon.Count)
                {
                    sqlDataSourceDanhMucCon.Add(new SqlDataSource(Config._CONNECTSTRING,
                        "SELECT TOP (6) MaTinRaoVat, TenTinRaoVat, Thumbnail, GiaTien, NoiDungTinRaoVat, ThoiGianDang, SoLanXem, MaDiaDiem, MaNguoiDung, MaDanhMucCon, MaNgonNgu, Deleted FROM TINRAOVAT WHERE MaDanhMucCon = " + danhMucCon[i].MaDanhMucCon + "ORDER BY ThoiGianUp DESC"));
                }
                else
                {
                    sqlDataSourceDanhMucCon.Add(new SqlDataSource());
                }

                sqlDataSourceDanhMucCon[i].ID = "sqlDataSourceDanhMucCon" + i.ToString();//
                sqlDataSourceDanhMucCon[i].DataBind();
                this.Controls.Add(sqlDataSourceDanhMucCon[i]);
            }

            DataBind();
        }

        protected void Page_PreInit(object sender, EventArgs e)
        {
            Page.Theme = ((XmlElement)XL_XML.ReadNodeSingle(XL_XML.ReadDocumentFile(Server.MapPath("Gui.xml")),
            "/GIAODIEN/THEME")).GetAttribute("ten");
        }

        public void setSession(int k)
        {
            Session["Madanhmuccon"] = k;
        }
    }
}
